﻿Public Class clsProdInfo
    Public Function getProdInfoByProdId(prod_id As String, status As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT prod_id,a.prod_spec_id,b.prod_spec_name,steel_seal_no,pq_ope,pq_dt FROM sf.b_prod_info a "
        szSql &= " left join sf.t_prod_spec b on a.prod_spec_id = b.prod_spec_id "
        szSql &= "WHERE a.factory_id = ? and a.prod_id = ? and a.status = ? and pq_ope is not null and pq_dt is not null"
        Return DBacs.ExecuteSql(szSql, -1, "TS", prod_id, status)
    End Function

    Public Function getProdInfoListPQjc(startTime As String, endTime As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT prod_id,a.prod_spec_id,b.prod_spec_name,steel_seal_no,pq_jc_ope,pq_jc_dt FROM sf.b_prod_info a "
        szSql &= " left join sf.t_prod_spec b on a.prod_spec_id = b.prod_spec_id "
        szSql &= "WHERE a.factory_id = ? "
        If startTime <> "" Then
            szSql &= " and a.pq_jc_dt >= '" + startTime + "'"
        End If
        If endTime <> "" Then
            szSql &= " and a.pq_jc_dt <= '" + endTime + "'"
        End If
        Return DBacs.ExecuteSql(szSql, -1, "TS")
    End Function

    Public Function getProdInfoByStatus(status As String, jiance As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT prod_id,a.prod_spec_id,b.prod_spec_name,steel_seal_no,pq_jc_ope,pq_jc_dt FROM sf.b_prod_info a "
        szSql &= " left join sf.t_prod_spec b on a.prod_spec_id = b.prod_spec_id "
        szSql &= "WHERE a.factory_id = ? and a.status = ? and pq_jc_ope is not null and pq_jc_dt is not null"
        Return DBacs.ExecuteSql(szSql, -1, "TS", status)
    End Function

    Public Function getProdInfoByStatus(status As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT prod_id,a.prod_spec_id,b.prod_spec_name,steel_seal_no,pq_ope,pq_dt FROM sf.b_prod_info a "
        szSql &= " left join sf.t_prod_spec b on a.prod_spec_id = b.prod_spec_id "
        szSql &= "WHERE a.factory_id = ? and a.status = ? "
        Return DBacs.ExecuteSql(szSql, -1, "TS", status)
    End Function

    Public Function getProdInfoByProdIdAndStatus(prod_id As String, status As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT * FROM sf.b_prod_info WHERE factory_id=? and prod_id = ? and status = ? "
        Return DBacs.ExecuteSql(szSql, -1, "TS", prod_id, status)
    End Function


    Public Function updateProdInfoPqjc(prod_ids As String, oper As String) As Integer
        Dim sql As String
        Dim rtn As Integer
        DBacs.BeginTransaction()
        Try
            sql = "update sf.b_prod_info set pq_jc_ope = ?, pq_jc_dt = (SELECT CURRENT_TIMESTAMP(6)), "
            sql &= "status = ?,update_time=(SELECT CURRENT_TIMESTAMP(6))"
            sql &= " where factory_id = ? and prod_id in ("
            sql &= prod_ids
            sql &= ") "
            Dim opn As Integer = Integer.Parse(Double.Parse("1"))
            rtn = DBacs.ExecuteUpdateSql(sql, -1, oper, "15", "TS", prod_ids)
            sql = "select prod_id,pgd_id,b_pgd_yzz_details_sys_id from sf.b_prod_info "
            sql &= " where factory_id = ? and prod_id in ("
            sql &= prod_ids
            sql &= ") "
            Dim dt As DataTable = DBacs.ExecuteSql(sql, -1, "TS", prod_ids)
            For index = 0 To dt.Rows.Count - 1
                sql = "select * from sf.b_pgd_mes_workreport where workshop_id = ? and prod_id = ? "
                Dim dtxx As DataTable = DBacs.ExecuteSql(sql, -1, "5", dt.Rows(index)("prod_id"))
                If dtxx.Rows.Count = 0 Then
                    sql = "INSERT INTO sf.b_pgd_mes_workreport(oper_type, b_pgd_mes_sys_id,oper_num, operator, update_time, prod_id, workshop_id, mes_sync_result)  "
                    sql &= "VALUES ( ?, ?, ?, ?, (SELECT CURRENT_TIMESTAMP(6)), ?, ?, ?)"
                    rtn = DBacs.ExecuteUpdateSql(sql, -1， "ok", dt.Rows(index)("pgd_id"), opn, oper, dt.Rows(index)("prod_id"), "5", String.Empty)
                End If
            Next
            DBacs.CommitTransaction()
        Catch ex As Exception
            DBacs.RollbackTransaction()
            rtn = -2
        End Try
        Return rtn
    End Function


End Class
